<script setup lang="ts">
import { useUserStore } from '@/stores/user'

import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
async function auth() {
  if (!route.query.code) {
    router.replace({ path: '/error/403' })
    return
  }
  var user = useUserStore()
  try {
    let result = await user.loginByCode(route.query.code as string)
    if (result.result == true) {
      router.replace({ path: '/', query: {} })
    } else {
      router.replace({ path: '/bind', query: { id: result.id } })
    }
  } catch (error) {
    console.log(error)
    router.replace({ path: '/error/403' })
  }
}
auth()
</script>

<template></template>
<style scoped></style>
